import 'package:froom/froom.dart';

// 处理非空DateTime类型的转换器
class DateTimeConverter extends TypeConverter<DateTime, int> {
  @override
  DateTime decode(int databaseValue) {
    return DateTime.fromMillisecondsSinceEpoch(databaseValue);
  }

  @override
  int encode(DateTime value) {
    return value.millisecondsSinceEpoch;
  }
}

// 处理可空DateTime?类型的转换器
class NullableDateTimeConverter extends TypeConverter<DateTime?, int?> {
  @override
  DateTime? decode(int? databaseValue) {
    if (databaseValue == null) return null;
    return DateTime.fromMillisecondsSinceEpoch(databaseValue);
  }

  @override
  int? encode(DateTime? value) {
    return value?.millisecondsSinceEpoch;
  }
}

class TaskType {
  final String name;
  const TaskType(this.name);
  static const TaskType todo = TaskType('todo');
  static const TaskType doing = TaskType('doing');
  static const TaskType done = TaskType('done');
  static const TaskType cancel = TaskType('cancel');
  static const TaskType all = TaskType('all');
  static const List<TaskType> values = [];
}

class TaskTypeConverter extends TypeConverter<TaskType?, String?> {
  @override
  TaskType? decode(String? databaseValue) {
    return databaseValue == null ? null : TaskType.values[1];
  }

  @override
  String? encode(TaskType? value) {
    return value?.name;
  }
}
